*------------------------------------*
* Party Strength and Economic Growth *
*------------------------------------*

*----------------
* Analysis codes
*----------------

*--------
* Table 1. Main Tests
*--------

eststo clear

* Load data
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

* Model 1 - Full OLS 1 year
eststo mod1: xtreg F.e_migdpgro ps e_migdppcln i.year, fe vce(cluster country_id)

* Model 2 - Full OLS 1 year, MOC
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_posterior_data.dta", clear
xtset, clear
xtset country_id year

* Set Matrix Size to fit analysis
set matsize 5000

***Monte Carlo Estimates Using UDS 3202 Draw Posterior Distribution***
*Run the monte carlo

forvalues i = 1/9 {

*Print out an iteration number
display `i'

*Fit the model, using the ith draw from the UDS posterior
quietly xtreg F.e_migdpgro ps_`i' e_migdppcln i.year, fe vce(cluster country_id) 

*Extract the coefficients and variance-covariance matrix
matrix b = e(b)
matrix V = e(V)
local blength = colsof(b)

*Preserve the dataset, take a single multivariate normal draw from the
*posterior distribution of the coefficients, and restore the dataset.
*We use the capture command to catch possible errors in drawnorm
*and drop these iterations gracefully.
preserve 
capture quietly drawnorm b1-b`blength', double n(1) means(b) cov(V) clear
if _rc==0 {
mkmat b1-b`blength', matrix(bsample)
matrix posterior = nullmat(posterior) \ bsample
}
else {
display "Error drawing sample...iteration dropped"
}
restore

*Closes the Monte Carlo Loop
}

*Get posterior ready to work with
svmat posterior

*Calculate means and standard deviations
tabstat posterior*, stat(mean sem p95)

*Find the bounds of the 95 percent credible interval
centile posterior*, centile(2.5, 97.5)

* Model 3 - Imputed
clear
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps.imput.dta"

mi import flong, m(m) id(country_id year) clear
mi xtset country_id year

eststo mod3 :mi est, post: xtreg F.e_migdpgro ps e_migdppcln i.year if year < 2010, fe vce(cluster country_id)

* Results need to be included by hand

* Model 4 - Ordinal
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

eststo mod4: xtreg F.e_migdpgro i.ps_ord e_migdppcln i.year, fe vce(cluster country_id)

* Model 5 - Full OLS 5 years
drop trend
drop if e_migdpgro_5yr == .
by country_id: gen trend = _n 
xtset, clear
xtset country_id trend
eststo mod5: xtreg F.e_migdpgro_5yr ps_5yr e_migdppcln_5yr i.year, fe vce(cluster country_id) 

* Model 6 - Stock
eststo mod6: xtreg F.e_migdpgro ps_stock e_migdppcln i.year, fe vce(cluster country_id)

* Model 7 - Lagged DV
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

eststo mod7: xtreg F.e_migdpgro ps e_migdpgro e_migdppcln i.year, fe vce(cluster country_id)

* Model 8 - Full Sys GMM 5 years
drop trend
drop if e_migdpgro_5yr == .
by country_id: gen trend = _n 
xtset, clear
xtset country_id trend
eststo mod8: xi: xtabond2 F.e_migdpgro_5yr e_migdpgro_5yr ps_5yr e_migdppcln_5yr i.year, gmm(ps_5yr e_migdpgro_5yr, lag (2 3)) iv(i.year) robust

* Model 9 - IV
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

eststo mod9: xi: xtivreg2 F.e_migdpgro e_migdppcln regiongrowth_minus globalgrowth_minus i.year (ps  = regionps_minus globalps_minus), fe robust cluster(country_id) first

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_paper_Table1.csv", ///
		b(3) se(3)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		keep(ps ps_5yr ps_stock 1.ps_ord 2.ps_ord 3.ps_ord 4.ps_ord e_migdppcln e_migdppcln_5yr e_migdpgro e_migdpgro_5yr) ///
		order(ps ps_5yr ps_stock 1.ps_ord 2.ps_ord 3.ps_ord 4.ps_ord e_migdppcln e_migdppcln_5yr e_migdpgro e_migdpgro_5yr) ///
		noconstant ///
		nogaps replace

*--------
* Figure 5. Marginal Effects 
*--------
* Load data
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

* Model 1 - Full OLS 1 year
eststo mod1: xtreg F.e_migdpgro ps e_migdppcln i.year, fe vce(cluster country_id)

* Marginal Effects (Graphed in R)
margins, at(ps = (-1.5 (0.5) 1.5))

*--------
* Table 2. Robustness Tests 
*--------

* Load data
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

* Model 1 - Spare OLS
eststo clear
eststo mod1: xtreg F.e_migdpgro ps i.year, fe vce(cluster country_id)

* Model 2 - First Diff Model
eststo mod2: xtreg F.e_migdpgro D.ps e_migdppcln i.year, fe vce(cluster country_id)

* Model 3 - General Covariates - Time Varying
eststo mod3: xtreg F.e_migdpgro ps e_migdppcln e_miurbani e_pelifeex e_mipetrol e_miinterc e_miinteco i.year, fe vce(cluster country_id)

* Model 4 - General Covariates - Fixed
eststo mod4: xtreg F.e_migdpgro ps e_migdppcln statehist5 al_ethnic lp_lat_abst_ln lp_muslim80 lp_protmg80 wdi_area i.lp_legor i.e_regionpol i.year, re vce(cluster country_id)

* Model 5 - Political Controls - V-Dem Set
eststo mod5: xtreg F.e_migdpgro ps e_migdppcln v2x_polyarchy liberties v2xcl_prpty law v2x_jucon v2xlg_legcon v2x_corr v2clstown v2xcs_ccsi i.year, fe vce(cluster country_id)

* Model 6 - Polity
eststo mod6: xtreg F.e_migdpgro ps e_migdppcln e_polity2 i.year, fe vce(cluster country_id)

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_paper_Table2.csv", ///
		b(3) se(3)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year) ///
		order(ps e_migdppcln) ///
		noconstant ///
		nogaps replace
		
*--------
* Table 3. Split samples 
*--------
eststo clear

* Model 1 - Minus sub-Saharan Africa
eststo mod1: xtreg F.e_migdpgro ps e_migdppcln i.year if ssafrica != 1, fe vce(cluster country_id)

* Model 2 - Minus Asia-Pacific
eststo mod2: xtreg F.e_migdpgro ps e_migdppcln i.year if asia != 1, fe vce(cluster country_id)

* Model 3 - Minus Former Soviet
eststo mod3: xtreg F.e_migdpgro ps e_migdppcln i.year if easteur != 1, fe vce(cluster country_id)

* Model 4 - Minus Latin America
eststo mod4: xtreg F.e_migdpgro ps e_migdppcln i.year if latam != 1, fe vce(cluster country_id)

* Model 5 - Minus MENA
eststo mod5: xtreg F.e_migdpgro ps e_migdppcln i.year if mena != 1, fe vce(cluster country_id)

* Model 6 - Western
eststo mod6: xtreg F.e_migdpgro ps e_migdppcln i.year if west == 1, fe vce(cluster country_id)

* Model 7 - Non-Western
eststo mod7: xtreg F.e_migdpgro ps e_migdppcln i.year if west == 0, fe vce(cluster country_id)

* Model 8 - Democracies
eststo mod8: xtreg F.e_migdpgro ps e_migdppcln i.year if e_boix_regime == 1, fe vce(cluster country_id)

* Model 9 - Autocracies
eststo mod9: xtreg F.e_migdpgro ps e_migdppcln i.year if e_boix_regime == 0, fe vce(cluster country_id)

* Model 10 - Prior to 1945
eststo mod10: xtreg F.e_migdpgro ps e_migdppcln i.year if year<1946, fe vce(cluster country_id)

* Model 11 - Post-1945
eststo mod11: xtreg F.e_migdpgro ps e_migdppcln i.year if year>1945, fe vce(cluster country_id)

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_paper_Table3.csv", ///
		b(3) se(3)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year) ///
		order(ps e_migdppcln ) ///
		noconstant ///
		nogaps replace
		
*--------
* Table 4. Party Strength and Growth Episodes
*--------
eststo clear

* Negative Growth
generate neggrowth =.
replace neggrowth = 0 if e_migdpgro !=.
replace neggrowth = 1 if e_migdpgro <0 & e_migdpgro !=.
eststo mod1: xtreg F.neggrowth ps e_migdppcln i.year, fe vce(cluster country_id)

* Sustained Growth (5 years)
generate fiveyearposgrowth = .
replace fiveyearposgrowth = 0 if e_migdpgro!=. & F.e_migdpgro!=. & F2.e_migdpgro!=. & F3.e_migdpgro!=. & F4.e_migdpgro!=.
replace fiveyearposgrowth = 1 if e_migdpgro!=. & F.e_migdpgro!=. & F2.e_migdpgro!=. & F3.e_migdpgro!=. & F4.e_migdpgro!=. & e_migdpgro>0 & F.e_migdpgro>0 & F2.e_migdpgro>0 & F3.e_migdpgro>0 & F4.e_migdpgro>0
eststo mod2: xtreg F.fiveyearposgrowth ps e_migdppcln i.year, fe vce(cluster country_id)

* Growth SD (10 years)
generate mean10growth=.
replace mean10growth = (e_migdpgro+F1.e_migdpgro+F2.e_migdpgro+F3.e_migdpgro+F4.e_migdpgro+ F5.e_migdpgro+F6.e_migdpgro+F7.e_migdpgro+F8.e_migdpgro+F9.e_migdpgro)/10 if e_migdpgro!=. & F.e_migdpgro!=. & F2.e_migdpgro!=. & F3.e_migdpgro!=. & F4.e_migdpgro!=. & F5.e_migdpgro!=. & F6.e_migdpgro!=. & F7.e_migdpgro!=. & F8.e_migdpgro!=. & F9.e_migdpgro!=.
generate stddev10growth=.
replace stddev10growth =  sqrt(((e_migdpgro-mean10growth)^2 + (F1.e_migdpgro-mean10growth)^2 +(F2.e_migdpgro-mean10growth)^2 +(F3.e_migdpgro-mean10growth)^2 +(F4.e_migdpgro-mean10growth)^2 + (F5.e_migdpgro-mean10growth)^2 + (F6.e_migdpgro-mean10growth)^2 +(F7.e_migdpgro-mean10growth)^2 +(F8.e_migdpgro-mean10growth)^2 +(F9.e_migdpgro-mean10growth)^2 )/10)  if e_migdpgro!=. & F.e_migdpgro!=. & F2.e_migdpgro!=. & F3.e_migdpgro!=. & F4.e_migdpgro!=. & F5.e_migdpgro!=. & F6.e_migdpgro!=. & F7.e_migdpgro!=. & F8.e_migdpgro!=. & F9.e_migdpgro!=.
eststo mod3: xtpcse F.stddev10growth ps e_migdppcln i.year, correlation(psar1) hetonly pairwise

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_paper_Table4.csv", ///
		b(3) se(3)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year) ///
		order(ps e_migdppcln) ///
		noconstant ///
		nogaps replace

*==============================================================================*

*------------------
* Appendix Tables
*------------------

*--------
* Appendix D
*--------

		
*--------
* Table C1. Convergent Validity, GWF
*--------
eststo clear

label define lab 1 "Democracy" 2 "Indirect Military" 3 "Military" 4 "Military / Personal" 5 "Monarchy" 6 "Oligarchy" 7 "Party" 8 "Party-Military" 9 "Party-Military-Personal" 10 "Party-Personal" 11 "Personal"  , modify
label values gwf_regimetype_num lab
eststo c1: reg ps ib11.gwf_regimetype_num, vce(cluster country_id)

esttab c1 using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_paper_C1.csv", ///
		b(3) se(3)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		noconstant ///
		nogaps replace
	
*--------
* Table C2. Convergent Validity, Hadenius & Teorell
*--------
eststo c2: reg ps ib1.ht_regtype, vce(cluster country_id)

esttab c2 using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_paper_C2.csv", ///
		b(3) se(3)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		noconstant ///
		nogaps replace
		
*--------
* Table C3. Convergent Validity, Correlations with party, governance, AND state capacity variables
*--------
eststo clear

corrtab  ps partyage total_EV_vote bti_q5 e_wbgi_cce e_wbgi_gee e_wbgi_pse e_wbgi_rle e_wbgi_rqe e_wbgi_vae v2clrspct Capacity taxratio statehist5, obs sig
corrtab  ps v2x_polyarchy e_polity2 e_wbgi_cce e_wbgi_gee e_wbgi_pse e_wbgi_rle e_wbgi_rqe e_wbgi_vae , obs sig
corrtab  ps v2clrspct Capacity taxratio statehist5, obs sig

*--------
* Appendix G
*--------

*--------
* Table G1. Alternate Indices
*--------

use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

* Model 1 - Benchmark
eststo clear
eststo mod1: xtreg F.e_migdpgro ps e_migdppcln i.year, fe vce(cluster country_id)

* Model 2 - Strucutural Variables
eststo mod2: xtreg F.e_migdpgro ps_8 e_migdppcln i.year, fe vce(cluster country_id)

* Model 3 - PCA
eststo mod3: xtreg F.e_migdpgro ps_pca e_migdppcln i.year, fe vce(cluster country_id)

* Model 4 - No Switching
eststo mod4: xtreg F.e_migdpgro ps_1 e_migdppcln i.year, fe vce(cluster country_id)

* Model 5 - No Cohesion
eststo mod5: xtreg F.e_migdpgro ps_2 e_migdppcln i.year, fe vce(cluster country_id)

* Model 6 - No Candidate Selection
eststo mod6: xtreg F.e_migdpgro ps_3 e_migdppcln i.year, fe vce(cluster country_id)

* Model 7 - No Linkages
eststo mod7: xtreg F.e_migdpgro ps_4 e_migdppcln i.year, fe vce(cluster country_id)

* Model 8 - No Organizations
eststo mod8: xtreg F.e_migdpgro ps_5 e_migdppcln i.year, fe vce(cluster country_id)

* Model 9 - No Branches
eststo mod9: xtreg F.e_migdpgro ps_6 e_migdppcln i.year, fe vce(cluster country_id)

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_paper_F1.csv", ///
		b(3) se(3)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year) ///
		noconstant ///
		nogaps replace

*--------
* Table G2. Indicators
*--------

use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

* Model 1 - Benchmark
eststo clear
eststo mod1: xtreg F.e_migdpgro ps e_migdppcln i.year, fe vce(cluster country_id)

* Model 2. Party Organizations
eststo mod2: xtreg F.e_migdpgro v2psorgs_std e_migdppcln i.year, fe vce(cluster country_id)

* Model 3. Party Branches
eststo mod3: xtreg F.e_migdpgro v2psprbrch_std e_migdppcln i.year, fe vce(cluster country_id)

* Model 4. Party Legislative Cohesion
eststo mod4: xtreg F.e_migdpgro v2pscohesv_std e_migdppcln i.year, fe vce(cluster country_id)

* Model 5. Candidate Selection National
eststo mod5: xtreg F.e_migdpgro v2pscnslnl_neg_std e_migdppcln i.year, fe vce(cluster country_id)

* Model 6. Party Linkages
eststo mod6: xtreg F.e_migdpgro v2psprlnks_std e_migdppcln i.year, fe vce(cluster country_id)

* Model 7. Party Switching
eststo mod7: xtreg F.e_migdpgro v2psswitch_neg_std e_migdppcln i.year, fe vce(cluster country_id)

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_paper_F2.csv", ///
		b(3) se(3)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year) ///
		noconstant ///
		nogaps replace

*--------
* Table G3. Lags and Leads
*--------
		
eststo clear

* Lagged DV
eststo mod1: xtreg F.e_migdpgro ps e_migdpgro e_migdppcln i.year, fe vce(cluster country_id)

* Switch IV and DV
eststo mod2: xtreg F.ps e_migdpgro ps e_migdppcln i.year, fe vce(cluster country_id)
		
* 1 year lag (benchmark model)
eststo mod3: xtreg e_migdpgro L1.ps L1.e_migdppcln i.year, fe vce(cluster country_id)

* 5 year lag
eststo mod4: xtreg e_migdpgro L5.ps L5.e_migdppcln i.year, fe vce(cluster country_id)

* 10 year lag
eststo mod5: xtreg e_migdpgro L10.ps L10.e_migdppcln i.year, fe vce(cluster country_id)

* 20 yeal lag
eststo mod6: xtreg e_migdpgro L20.ps L20.e_migdppcln i.year, fe vce(cluster country_id)

* 1 year lead
eststo mod7: xtreg e_migdpgro F1.ps F1.e_migdppcln i.year, fe vce(cluster country_id)

* 5 year lead
eststo mod8: xtreg e_migdpgro F5.ps F5.e_migdppcln i.year, fe vce(cluster country_id)

* 10 year lead
eststo mod9: xtreg e_migdpgro F10.ps F10.e_migdppcln i.year, fe vce(cluster country_id)

* 20 year lead
eststo mod10: xtreg e_migdpgro F20.ps F20.e_migdppcln i.year, fe vce(cluster country_id)

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_extension_lagsleads.csv", ///
		b(2) se(2)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year) ///
		order(L.ps L5.ps L10.ps L20.ps F.ps F5.ps F10.ps F20.ps L1.e_migdppcln L5.e_migdppcln L10.e_migdppcln L20.e_migdppcln F1.e_migdppcln F5.e_migdppcln F10.e_migdppcln F20.e_migdppcln) ///
		noconstant ///
		nogaps replace
		
*---------
* Table G4. Long differences (1960-2000)
*---------
eststo clear

* Full Sample
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear

keep if year == 1960 | year == 2000
keep if ps != . & e_migdppcln != .
sort country_id year
by country_id: replace trend= _n
drop if year == 2006 & trend == 1
drop if trend == trend[_n+1]

xtset country_id year
eststo mod1: xtreg e_migdppcln ps i.year, fe vce(cluster country_id)
		
* Democracies
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear

keep if year == 1960 | year == 2000
keep if ps != . & e_migdppcln != . & e_boix_regime == 1 
sort country_id year
by country_id: replace trend= _n
drop if year == 2006 & trend == 1
drop if trend == trend[_n+1]

xtset country_id year
eststo mod2: xtreg e_migdppcln ps i.year, fe vce(cluster country_id)

* Autocracies
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear

keep if year == 1960 | year == 2000
keep if ps != . & e_migdppcln != . & e_boix_regime == 0 
sort country_id year
by country_id: replace trend= _n
drop if year == 2006 & trend == 1
drop if trend == trend[_n+1]

xtset country_id year
eststo mod3: xtreg e_migdppcln ps i.year, fe vce(cluster country_id)

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_extension_longdifferences.csv", ///
		b(2) se(2)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year) ///
		noconstant ///
		nogaps replace

*---------
* Table G5. GEE Models
*---------
eststo clear

* Benchmark
eststo mod1: xtgee F.e_migdpgro ps e_migdppcln i.year, corr(exchangeable) vce(robust) force

* AR-1
eststo mod2: xtgee F.e_migdpgro ps e_migdppcln i.year, corr(ar1) vce(robust) force

* AR-2
eststo mod3: xtgee F.e_migdpgro ps e_migdppcln i.year, corr(ar2) vce(robust) force

* AR-5
eststo mod4: xtgee F.e_migdpgro ps e_migdppcln i.year, corr(ar5) vce(robust) force

* AR-10
eststo mod5: xtgee F.e_migdpgro ps e_migdppcln i.year, corr(ar10) vce(robust) force

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_extension_gee.csv", ///
		b(2) se(2)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label ///
		mtitles("Exchangeable" "AR-1" "AR-2" "AR-5" "AR-10") ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year) order(ps e_migdppcln) ///
		noconstant ///
		nogaps replace

*---------
* Figure G1. Roling Regression models
*---------

rolling _b _se, window(30): reg F.e_migdpgro ps e_migdppcln i.year, robust


*---------
* Table G6. Regional and Decade Dummies
*---------
	
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

* Generate Decade dummies
gen decade = 1
replace decade = 2 if year > 1909
replace decade = 3 if year > 1919
replace decade = 4 if year > 1929
replace decade = 5 if year > 1939
replace decade = 6 if year > 1949
replace decade = 7 if year > 1959
replace decade = 8 if year > 1969
replace decade = 9 if year > 1979
replace decade = 10 if year > 1989
replace decade = 11 if year > 1999
replace decade = 12 if year > 2009

eststo clear

eststo mod1: xtreg F.e_migdpgro ps e_migdppcln i.year, fe vce(cluster country_id)
eststo mod2: reg F.e_migdpgro ps e_migdppcln i.decade##ssafrica i.decade##easteur i.decade##asia i.decade##latam i.decade##mena, vce(cluster e_regionpol)
eststo mod3: xtreg F.e_migdpgro ps e_migdppcln i.decade##ssafrica i.decade##easteur i.decade##asia i.decade##latam i.decade##mena, re vce(cluster e_regionpol)

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_extension_regional.csv", ///
		b(2) se(2)  ///
		stats(N N_g g_min g_avg g_max r2_w r2, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)" "R-squared")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year *.decade *.mena *.latam *.ssafrica *.asia *.easteur *.decade#*) order(ps e_migdppcln) ///
		noconstant ///
		nogaps replace

*--------
* Table G7. Disaggregated V-Dem indices
*--------

use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

eststo clear

* Specification texts for model 5 in Table 2
eststo mod1: xtreg F.e_migdpgro ps e_migdppcln v2clrspct i.year, fe vce(cluster country_id)
eststo mod2: xtreg F.e_migdpgro ps e_migdppcln v2cltrnslw i.year, fe vce(cluster country_id)
eststo mod3: xtreg F.e_migdpgro ps e_migdppcln v2xcl_prpty i.year, fe vce(cluster country_id)
eststo mod4: xtreg F.e_migdpgro ps e_migdppcln v2xcl_acjst i.year, fe vce(cluster country_id)
eststo mod5: xtreg F.e_migdpgro ps e_migdppcln v2cltort i.year, fe vce(cluster country_id)
eststo mod6: xtreg F.e_migdpgro ps e_migdppcln v2clkill i.year, fe vce(cluster country_id)
eststo mod7: xtreg F.e_migdpgro ps e_migdppcln v2xcl_slave i.year, fe vce(cluster country_id)
eststo mod8: xtreg F.e_migdpgro ps e_migdppcln v2clrelig i.year, fe vce(cluster country_id)
eststo mod9: xtreg F.e_migdpgro ps e_migdppcln v2clfmove i.year, fe vce(cluster country_id)
eststo mod10: xtreg F.e_migdpgro ps e_migdppcln v2xcl_dmove i.year, fe vce(cluster country_id)

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_paper_H1.csv", ///
		b(3) se(3)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year) ///
		noconstant ///
		nogaps replace

*--------
* Table G8. Interaction models
*--------

* Interaction with regime (e_boix_regime)
gen inter_reg1 = ps * e_boix_regime

* Interaction with regime (polity)
gen inter_reg2 = ps * e_polity2

eststo h1: xtreg F.e_migdpgro ps e_boix_regime inter_reg1 e_migdppcln i.year, fe vce(cluster country_id)
eststo h2: xtreg F.e_migdpgro ps e_polity2 inter_reg2 e_migdppcln i.year, fe vce(cluster country_id)

* Interaction with time
gen after45 = 1 if year >= 1946
replace after45 = 0 if after45 == . & year < 1946
gen inter_time1 = ps * after45
eststo h3: xtreg F.e_migdpgro ps after45 inter_time1 e_migdppcln i.year, fe vce(cluster country_id)

* Interaction with regions
gen inter_PostC = .
gen inter_Lat = .
gen inter_MENA = .
gen inter_Sub = .
gen inter_West = .
gen inter_EAsia = .
gen inter_SEAsia = .
gen inter_SAsia = .
gen inter_Pac = .
gen inter_Crb = .

replace inter_PostC = ps if e_regionpol == 1
replace inter_PostC = 0 if e_regionpol != 1
replace inter_Lat = ps if e_regionpol == 2
replace inter_Lat = 0 if e_regionpol != 2
replace inter_MENA = ps if e_regionpol == 3
replace inter_MENA = 0 if e_regionpol != 3
replace inter_Sub = ps if e_regionpol == 4
replace inter_Sub = 0 if e_regionpol != 4
replace inter_West = ps if e_regionpol == 5
replace inter_West = 0 if e_regionpol != 5
replace inter_EAsia = ps if e_regionpol == 6
replace inter_EAsia = 0 if e_regionpol != 6
replace inter_SEAsia = ps if e_regionpol == 7
replace inter_SEAsia = 0 if e_regionpol != 7
replace inter_SAsia = ps if e_regionpol == 8
replace inter_SAsia = 0 if e_regionpol != 8
replace inter_Pac = ps if e_regionpol == 9
replace inter_Pac = 0 if e_regionpol != 9
replace inter_Crb = ps if e_regionpol == 10
replace inter_Crb = 0 if e_regionpol != 10

eststo h4: xtreg F.e_migdpgro ps e_migdppcln ib5.e_regionpol inter_PostC inter_Lat inter_MENA inter_Sub inter_EAsia inter_SEAsia inter_SAsia inter_Crb i.year, re

esttab h* using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_paper_J1.csv", ///
		b(3) se(3)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year) order(ps e_migdppcln) ///
		noconstant ///
		nogaps replace

*--------
* Table G9. Benchmark with samples
*--------	
		
* Load data
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

* Model 2 - First Diff Model
eststo mod2: xtreg F.e_migdpgro D.ps e_migdppcln i.year, fe vce(cluster country_id)
eststo mod2b: xtreg F.e_migdpgro ps e_migdppcln i.year if _est_mod2 == 1, fe vce(cluster country_id)

* Model 3 - General Covariates - Time Varying
eststo mod3: xtreg F.e_migdpgro ps e_migdppcln e_miurbani e_pelifeex e_mipetrol e_miinterc e_miinteco i.year, fe vce(cluster country_id)
eststo mod3b: xtreg F.e_migdpgro ps e_migdppcln i.year if _est_mod3 == 1, fe vce(cluster country_id)

* Model 4 - General Covariates - Fixed
eststo mod4: xtreg F.e_migdpgro ps e_migdppcln statehist5 al_ethnic lp_lat_abst_ln lp_muslim80 lp_protmg80 wdi_area i.lp_legor i.e_regionpol i.year, re vce(cluster country_id)
eststo mod4b: xtreg F.e_migdpgro ps e_migdppcln i.year if _est_mod4 == 1, fe vce(cluster country_id)

* Model 5 - Political Controls - V-Dem Set
eststo mod5: xtreg F.e_migdpgro ps e_migdppcln v2x_polyarchy liberties v2xcl_prpty law v2x_jucon v2xlg_legcon v2x_corr v2clstown v2xcs_ccsi i.year, fe vce(cluster country_id)
eststo mod5b: xtreg F.e_migdpgro ps e_migdppcln i.year if _est_mod5 == 1, fe vce(cluster country_id)

* Model 6 - Polity
eststo mod6: xtreg F.e_migdpgro ps e_migdppcln e_polity2, fe vce(cluster country_id)
eststo mod6b: xtreg F.e_migdpgro ps e_migdppcln i.year if _est_mod6 == 1, fe vce(cluster country_id)

esttab mod2b mod3b mod4b mod5b mod6b   using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_2_benchmarks.csv", ///
		b(2) se(2)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year) ///
		noconstant ///
		nogaps replace

*--------
* Table G11. Presidential v. Parliamentary
*---------

eststo clear

* Reload full data
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

* Benchmark with observations with data on Government type
eststo mod1: xtreg F.e_migdpgro ps e_migdppcln i.year if pres != ., fe vce(cluster country_id)

* Controlling for 

* Government type, 4 categories
eststo mod2: xtreg F.e_migdpgro ps e_migdppcln i.pres i.year, fe vce(cluster country_id)

* Government type, binary
eststo mod3: xtreg F.e_migdpgro ps e_migdppcln i.pres2 i.year, fe vce(cluster country_id)

* Interaction
eststo mod4: xtreg F.e_migdpgro ps pres2##c.ps e_migdppcln i.year, fe vce(cluster country_id)

* Split-sample

* Presidential system
eststo mod5: xtreg F.e_migdpgro ps e_migdppcln i.year if pres2 == 1, fe vce(cluster country_id)

* Parliamentary system
eststo mod6: xtreg F.e_migdpgro ps e_migdppcln i.year if pres2 == 0, fe vce(cluster country_id)

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_extension_presidentialism.csv", ///
		b(2) se(2)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year 1.pres 0.pres2 0.pres2#c.ps) ///
		noconstant ///
		nogaps replace
		
*--------
* Table G12. Electoral Systems
*--------	

eststo clear

* Reload full data
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

gen v2elparlel2 = v2elparlel
replace v2elparlel2 = 1 if v2elparlel2 == 2

* Benchmark with observations with data on Government type
eststo mod1: xtreg F.e_migdpgro ps e_migdppcln i.year if v2elparlel2 != ., fe vce(cluster country_id)

* Electoral system, binary
eststo mod3: xtreg F.e_migdpgro ps e_migdppcln i.v2elparlel2 i.year, fe vce(cluster country_id)

* Interaction
eststo mod4: xtreg F.e_migdpgro i.v2elparlel2##c.ps e_migdppcln i.year, fe vce(cluster country_id)

* Split-sample

* Majoritarian system
eststo mod5: xtreg F.e_migdpgro ps e_migdppcln i.year if v2elparlel == 0, fe vce(cluster country_id)

* Proportional systems
eststo mod6: xtreg F.e_migdpgro ps e_migdppcln i.year if v2elparlel == 1, fe vce(cluster country_id)

esttab _all  using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_extension_elecsyst.csv", ///
		b(2) se(2)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year 0.v2elparlel2 0.v2elparlel2#c.ps) ///
		noconstant ///
		nogaps replace
		
*--------
* Table G13. State Capacity, V-Dem Public Administration Variable
*--------
eststo clear

use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

* Benchmark
eststo mod1: xtreg F.e_migdpgro ps e_migdppcln i.year if v2clrspct != ., fe vce(cluster country_id)

* Only control
eststo mod2: xtreg F.e_migdpgro v2clrspct e_migdppcln i.year if ps != ., fe vce(cluster country_id)

* Add control
eststo mod3: xtreg F.e_migdpgro ps v2clrspct e_migdppcln i.year, fe vce(cluster country_id)

* Interaction
eststo mod4: xtreg F.e_migdpgro c.ps##c.v2clrspct e_migdppcln i.year, fe vce(cluster country_id)

* Democracies 
eststo mod5: xtreg F.e_migdpgro ps v2clrspct e_migdppcln i.year if e_boix_regime == 1, fe vce(cluster country_id)

* Authocracies
eststo mod6: xtreg F.e_migdpgro ps v2clrspct e_migdppcln i.year if e_boix_regime == 0, fe vce(cluster country_id)

* After 1946
eststo mod7: xtreg F.e_migdpgro ps v2clrspct e_migdppcln i.year if year > 1945, fe vce(cluster country_id)

* Not West
eststo mod8: xtreg F.e_migdpgro ps v2clrspct e_migdppcln i.year if west == 0, fe vce(cluster country_id)

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_extension_SC_v2clrspct.csv", ///
		b(2) se(2)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label ///
		mtitles("Only PS" "Only SC" "Both" "Interaction" "Democracies" "Autocracies" "After 1946" "Not Western") ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year) order(ps v2clrspct c.ps#c.v2clrspct e_migdppcln) ///
		noconstant ///
		nogaps replace
		
*--------
* Table G14. State Capacity, Hanson and Sigman
*--------
eststo clear

* Benchmark
eststo mod1: xtreg F.e_migdpgro ps e_migdppcln i.year if Capacity != ., fe vce(cluster country_id)

* Only control
eststo mod2: xtreg F.e_migdpgro Capacity e_migdppcln i.year if ps != ., fe vce(cluster country_id)

* Add control
eststo mod3: xtreg F.e_migdpgro ps Capacity e_migdppcln i.year, fe vce(cluster country_id)

* Interaction
eststo mod4: xtreg F.e_migdpgro c.ps##c.Capacity e_migdppcln i.year, fe vce(cluster country_id)

* Democracies 
eststo mod5: xtreg F.e_migdpgro ps Capacity e_migdppcln i.year if e_boix_regime == 1, fe vce(cluster country_id)

* Authocracies
eststo mod6: xtreg F.e_migdpgro ps Capacity e_migdppcln i.year if e_boix_regime == 0, fe vce(cluster country_id)

* After 1946
eststo mod7: xtreg F.e_migdpgro ps Capacity e_migdppcln i.year if year > 1945, fe vce(cluster country_id)

* Not West
eststo mod8: xtreg F.e_migdpgro ps Capacity e_migdppcln i.year if west == 0, fe vce(cluster country_id)

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_extension_SC_capacity.csv", ///
		b(2) se(2)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label ///
		mtitles("Only PS" "Only SC" "Both" "Interaction" "Democracies" "Autocracies" "After 1946" "Not Western") ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year) order(ps Capacity c.ps#c.Capacity e_migdppcln) ///
		noconstant ///
		nogaps replace
		
*--------
* Table G15. State Capacity, StateHist5
*--------
eststo clear

* Benchmark
eststo mod1: xtreg F.e_migdpgro ps e_migdppcln al_ethnic lp_lat_abst_ln lp_muslim80 lp_protmg80 wdi_area i.lp_legor i.e_regionpol i.year, re vce(cluster country_id)

* Only control
eststo mod2: xtreg F.e_migdpgro statehist5 e_migdppcln al_ethnic lp_lat_abst_ln lp_muslim80 lp_protmg80 wdi_area i.lp_legor i.e_regionpol i.year, re vce(cluster country_id)

* Add control
eststo mod3: xtreg F.e_migdpgro ps statehist5 e_migdppcln al_ethnic lp_lat_abst_ln lp_muslim80 lp_protmg80 wdi_area i.lp_legor i.e_regionpol i.year, re vce(cluster country_id)

* Interaction
eststo mod4: xtreg F.e_migdpgro c.ps##c.statehist5 e_migdppcln al_ethnic lp_lat_abst_ln lp_muslim80 lp_protmg80 wdi_area i.lp_legor i.e_regionpol i.year, re vce(cluster country_id)

* Democracies 
eststo mod5: xtreg F.e_migdpgro ps statehist5 e_migdppcln statehist5 al_ethnic lp_lat_abst_ln lp_muslim80 lp_protmg80 wdi_area i.lp_legor i.e_regionpol i.year if e_boix_regime == 1, re vce(cluster country_id)

* Authocracies
eststo mod6: xtreg F.e_migdpgro ps statehist5 e_migdppcln statehist5 al_ethnic lp_lat_abst_ln lp_muslim80 lp_protmg80 wdi_area i.lp_legor i.e_regionpol i.year if e_boix_regime == 0, re vce(cluster country_id)

* After 1946
eststo mod7: xtreg F.e_migdpgro ps statehist5 e_migdppcln al_ethnic lp_lat_abst_ln lp_muslim80 lp_protmg80 wdi_area i.lp_legor i.e_regionpol i.year if year > 1945, re vce(cluster country_id)

* Not West
eststo mod8: xtreg F.e_migdpgro ps statehist5 e_migdppcln al_ethnic lp_lat_abst_ln lp_muslim80 lp_protmg80 wdi_area i.lp_legor i.e_regionpol i.year if west != 1, re vce(cluster country_id)

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_extension_SC_statehist5.csv", ///
		b(2) se(2)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label ///
		mtitles("Only PS" "Only SC" "Both" "Interaction" "Democracies" "Autocracies" "After 1946" "Not Western") ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year) order(ps statehist5 c.ps#c.statehist5 e_migdppcln) ///
		noconstant ///
		nogaps replace

*--------
* Appendix H
*--------


*--------
* Table H1 - First Stage (2SLS) from Model 7, Table 2 *
*--------
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

eststo clear
*old
eststo mod: xi: xtivreg2 F.e_migdpgro e_migdppcln regiongrowth_minus globalgrowth_minus i.year (ps  = regionps_minus globalps_minus), fe first
*for RR
eststo mod: xi: xtivreg2 F.e_migdpgro e_migdppcln regiongrowth_minus globalgrowth_minus i.year (ps  = regionps_minus globalps_minus), fe robust cluster(country_id) first

*CHK testing extra specifications for appx text:
*eststo mod7: xi: xtivreg2 F.e_migdpgro e_migdppcln regiongrowth_minus globalgrowth_minus i.year (ps  = regionps_minus), fe robust cluster(country_id) first
	
*--------
* Table H2 - 2SLS, Alternative specifications *
*--------
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

eststo clear
generate year2=year

* Model 1
eststo mod1: xi: xtivreg2 F.e_migdpgro e_migdppcln regiongrowth_minus i.year (ps  = regionps_minus), fe robust cluster(country_id) first
* Model 2
eststo mod2: xi: xtivreg2 F.e_migdpgro e_migdppcln regiongrowth_minus globalgrowth_minus (ps  = regionps_minus globalps_minus), fe robust cluster(country_id) first
* Model 3
eststo mod3: xi: xtivreg2 F.e_migdpgro e_migdppcln regiongrowth_minus globalgrowth_minus year2 (ps  = regionps_minus globalps_minus), fe robust cluster(country_id) first
* Model 4
eststo mod4: xi: xtivreg2 F.e_migdpgro e_migdppcln year2 (ps  = regionps_minus globalps_minus), fe robust cluster(country_id) first
* Model 5
eststo mod5: xi: xtivreg F.e_migdpgro e_migdppcln regiongrowth_minus globalgrowth_minus i.year (ps  = regionps_minus globalps_minus), re first
* Model 6
eststo mod6: xi: xtivreg F.e_migdpgro e_migdppcln regiongrowth_minus globalgrowth_minus (ps  = regionps_minus globalps_minus), re first
* Model 7
eststo mod7: xi: xtivreg F.e_migdpgro e_migdppcln regiongrowth_minus globalgrowth_minus year2 (ps  = regionps_minus globalps_minus), re first

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_paper_E2.csv", ///
		b(3) se(3)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(year2 regiongrowth_minus globalgrowth_minus _Iyear_*) ///
		noconstant ///
		nogaps replace
			
*--------
* Table H3. GMM with Ln GDP pc as DV
*--------
xi: xtabond2 F.e_migdppcln_5yr ps_5yr e_migdppcln_5yr i.year, gmm(ps_5yr e_migdppcln_5yr, lag (2 3)) iv(i.year) robust
xi: xtabond2 F.e_migdppcln_5yr ps_5yr e_migdppcln_5yr L.e_migdppcln_5yr i.year, gmm(ps_5yr e_migdppcln_5yr L.e_migdppcln_5yr, lag (2 3)) iv(i.year) artests(3) robust

*--------
* Appendix I
*--------		
		
*--------
* Table I1. Party Strength and Economic Crisis
*--------
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

* Negative Growth
generate neggrowth =.
replace neggrowth = 0 if e_migdpgro !=.
replace neggrowth = 1 if e_migdpgro <0 & e_migdpgro !=.

generate minus3growth =.
replace minus3growth = 0 if e_migdpgro !=.
replace minus3growth = 1 if e_migdpgro <-3 & e_migdpgro !=.

generate minus5growth =.
replace minus5growth = 0 if e_migdpgro !=.
replace minus5growth = 1 if e_migdpgro <-5 & e_migdpgro !=.

* Model 1
eststo mod1: xtreg F.neggrowth ps e_migdppcln i.year, fe vce(cluster country_id)

* Model 2
eststo mod2: logit F.neggrowth ps e_migdppcln i.year i.country_id, vce(cluster country_id)

* Model 3
eststo mod3: xtreg F.minus3growth ps e_migdppcln i.year, fe vce(cluster country_id)

* Model 4
eststo mod4: logit F.minus3growth ps e_migdppcln i.year i.country_id, vce(cluster country_id)

* Model 5
eststo mod5: xtreg F.minus5growth ps e_migdppcln i.year, fe vce(cluster country_id)

* Model 6
eststo mod6: logit F.minus5growth ps e_migdppcln i.year i.country_id, vce(cluster country_id)

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_paper_F1.csv", ///
		b(3) se(3)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year *.country_id) ///
		noconstant ///
		nogaps replace
		
*--------
* Table I2 - Party Strength and Sustained Growth Episodes 
*--------
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

* Generating new vars
generate fiveyearposgrowth = .
replace fiveyearposgrowth = 0 if e_migdpgro!=. & F.e_migdpgro!=. & F2.e_migdpgro!=. & F3.e_migdpgro!=. & F4.e_migdpgro!=.
replace fiveyearposgrowth = 1 if e_migdpgro!=. & F.e_migdpgro!=. & F2.e_migdpgro!=. & F3.e_migdpgro!=. & F4.e_migdpgro!=. & e_migdpgro>0 & F.e_migdpgro>0 & F2.e_migdpgro>0 & F3.e_migdpgro>0 & F4.e_migdpgro>0

generate tenyearposgrowth = .
replace tenyearposgrowth = 0 if e_migdpgro!=. & F.e_migdpgro!=. & F2.e_migdpgro!=. & F3.e_migdpgro!=. & F4.e_migdpgro!=. & F5.e_migdpgro!=. & F6.e_migdpgro!=. & F7.e_migdpgro!=. & F8.e_migdpgro!=. & F9.e_migdpgro!=.
replace tenyearposgrowth = 1 if e_migdpgro!=. & F.e_migdpgro!=. & F2.e_migdpgro!=. & F3.e_migdpgro!=. & F4.e_migdpgro!=. & F5.e_migdpgro!=. & F6.e_migdpgro!=. & F7.e_migdpgro!=. & F8.e_migdpgro!=. & F9.e_migdpgro!=. & e_migdpgro>0 & F.e_migdpgro>0 & F2.e_migdpgro>0 & F3.e_migdpgro>0 & F4.e_migdpgro>0 & F5.e_migdpgro>0 & F6.e_migdpgro>0 & F7.e_migdpgro>0 & F8.e_migdpgro>0 & F9.e_migdpgro>0

generate fifteenyearposgrowth = .
replace fifteenyearposgrowth = 0 if e_migdpgro!=. & F.e_migdpgro!=. & F2.e_migdpgro!=. & F3.e_migdpgro!=. & F4.e_migdpgro!=. & F5.e_migdpgro!=. & F6.e_migdpgro!=. & F7.e_migdpgro!=. & F8.e_migdpgro!=. & F9.e_migdpgro!=. & F10.e_migdpgro!=. & F11.e_migdpgro!=. & F12.e_migdpgro!=. & F13.e_migdpgro!=. & F14.e_migdpgro!=.
replace fifteenyearposgrowth = 1 if e_migdpgro!=. & F.e_migdpgro!=. & F2.e_migdpgro!=. & F3.e_migdpgro!=. & F4.e_migdpgro!=. & F5.e_migdpgro!=. & F6.e_migdpgro!=. & F7.e_migdpgro!=. & F8.e_migdpgro!=. & F9.e_migdpgro!=. & F10.e_migdpgro!=. & F11.e_migdpgro!=. & F12.e_migdpgro!=. & F13.e_migdpgro!=. & F14.e_migdpgro!=. & e_migdpgro>0 & F.e_migdpgro>0 & F2.e_migdpgro>0 & F3.e_migdpgro>0 & F4.e_migdpgro>0 & F5.e_migdpgro>0 & F6.e_migdpgro>0 & F7.e_migdpgro>0 & F8.e_migdpgro>0 & F9.e_migdpgro>0 & F10.e_migdpgro>0 & F11.e_migdpgro>0 & F12.e_migdpgro>0 & F13.e_migdpgro>0 & F14.e_migdpgro>0

eststo clear

* Model 1
eststo mod1: xtreg F.fiveyearposgrowth ps e_migdppcln i.year, fe vce(cluster country_id)

* Model 2
eststo mod2: logit F.fiveyearposgrowth ps e_migdppcln i.year i.country_id, vce(cluster country_id)

* Model 3
eststo mod3: xtreg F.tenyearposgrowth ps e_migdppcln i.year, fe vce(cluster country_id)

* Model 4
eststo mod4: logit F.tenyearposgrowth ps e_migdppcln i.year i.country_id, vce(cluster country_id)

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_paper_F2.csv", ///
		b(3) se(3)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year *.country_id) ///
		noconstant ///
		nogaps replace
		
*--------
* Table I3 - Party Strength and Growth Volatility 
*--------

eststo clear

* Generating new vars
generate mean10growth=.
replace mean10growth = (e_migdpgro+F1.e_migdpgro+F2.e_migdpgro+F3.e_migdpgro+F4.e_migdpgro+ F5.e_migdpgro+F6.e_migdpgro+F7.e_migdpgro+F8.e_migdpgro+F9.e_migdpgro)/10 if e_migdpgro!=. & F.e_migdpgro!=. & F2.e_migdpgro!=. & F3.e_migdpgro!=. & F4.e_migdpgro!=. & F5.e_migdpgro!=. & F6.e_migdpgro!=. & F7.e_migdpgro!=. & F8.e_migdpgro!=. & F9.e_migdpgro!=.

generate mean15growth=.
replace mean15growth = (e_migdpgro+F1.e_migdpgro+F2.e_migdpgro+F3.e_migdpgro+F4.e_migdpgro+ F5.e_migdpgro+F6.e_migdpgro+F7.e_migdpgro+F8.e_migdpgro+F9.e_migdpgro+F10.e_migdpgro+F11.e_migdpgro+F12.e_migdpgro+F13.e_migdpgro+F14.e_migdpgro)/15 if e_migdpgro!=. & F.e_migdpgro!=. & F2.e_migdpgro!=. & F3.e_migdpgro!=. & F4.e_migdpgro!=. & F5.e_migdpgro!=. & F6.e_migdpgro!=. & F7.e_migdpgro!=. & F8.e_migdpgro!=. & F9.e_migdpgro!=. & F10.e_migdpgro!=. & F11.e_migdpgro!=. & F12.e_migdpgro!=. & F13.e_migdpgro!=. & F14.e_migdpgro!=.
summarize e_migdpgro mean15growth

generate stddev10growth=.
replace stddev10growth =  sqrt(((e_migdpgro-mean10growth)^2 + (F1.e_migdpgro-mean10growth)^2 +(F2.e_migdpgro-mean10growth)^2 +(F3.e_migdpgro-mean10growth)^2 +(F4.e_migdpgro-mean10growth)^2 + (F5.e_migdpgro-mean10growth)^2 + (F6.e_migdpgro-mean10growth)^2 +(F7.e_migdpgro-mean10growth)^2 +(F8.e_migdpgro-mean10growth)^2 +(F9.e_migdpgro-mean10growth)^2 )/10)  if e_migdpgro!=. & F.e_migdpgro!=. & F2.e_migdpgro!=. & F3.e_migdpgro!=. & F4.e_migdpgro!=. & F5.e_migdpgro!=. & F6.e_migdpgro!=. & F7.e_migdpgro!=. & F8.e_migdpgro!=. & F9.e_migdpgro!=.

generate stddev15growth=.
replace stddev15growth =  sqrt(((e_migdpgro-mean15growth)^2 + (F1.e_migdpgro-mean15growth)^2 +(F2.e_migdpgro-mean15growth)^2 +(F3.e_migdpgro-mean15growth)^2 +(F4.e_migdpgro-mean15growth)^2 + (F5.e_migdpgro-mean15growth)^2 + (F6.e_migdpgro-mean15growth)^2 +(F7.e_migdpgro-mean15growth)^2 +(F8.e_migdpgro-mean15growth)^2 +(F9.e_migdpgro-mean15growth)^2 + (F10.e_migdpgro-mean15growth)^2 + (F11.e_migdpgro-mean15growth)^2 +(F12.e_migdpgro-mean15growth)^2 +(F13.e_migdpgro-mean15growth)^2 +(F14.e_migdpgro-mean15growth)^2 )/15)  if e_migdpgro!=. & F.e_migdpgro!=. & F2.e_migdpgro!=. & F3.e_migdpgro!=. & F4.e_migdpgro!=. & F5.e_migdpgro!=. & F6.e_migdpgro!=. & F7.e_migdpgro!=. & F8.e_migdpgro!=. & F9.e_migdpgro!=. & F10.e_migdpgro!=. & F11.e_migdpgro!=. & F12.e_migdpgro!=. & F13.e_migdpgro!=. & F14.e_migdpgro!=.

* OLS, fe
eststo mod1: xtreg F.stddev10growth ps e_migdppcln i.year, fe vce(cluster country_id)

eststo mod2: xtreg F.stddev15growth ps e_migdppcln i.year, fe vce(cluster country_id)

eststo mod3: xtreg F.stddev10growth ps mean10growth e_migdppcln i.year, fe vce(cluster country_id)

eststo mod4: xtreg F.stddev15growth ps mean15growth e_migdppcln i.year, fe vce(cluster country_id)

* PCSE
eststo mod5: xtpcse F.stddev10growth ps e_migdppcln i.year, correlation(psar1) hetonly pairwise

eststo mod6: xtpcse F.stddev15growth ps e_migdppcln i.year, correlation(psar1) hetonly pairwise

eststo mod7: xtpcse F.stddev10growth ps mean10growth e_migdppcln i.year, correlation(psar1) hetonly pairwise

eststo mod8: xtpcse F.stddev15growth ps mean15growth e_migdppcln i.year, correlation(psar1) hetonly pairwise

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_paper_F3.csv", ///
		b(3) se(3)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year) ///
		noconstant ///
		nogaps replace

*--------
* Appendix J
*--------

*--------
* Table J1. Mediation Analysis
*--------

* Mediation analysis, properly
eststo clear

* Reload full data
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year
		
* Generate mediators (time apart)
gen gdpgro2 = F2.e_migdpgro
gen lifeex = ln(85-e_pelifeex)
gen lifeex1 = F1.lifeex
gen infmor = ln(e_peinfmor)
gen infmor1 = F1.infmor
gen invest1 = F1.pwt_isg
gen inflat = ln(e_miinflat)
gen inflat1 = F1.inflat
gen exitir1 = F1.exit_1_irregular
gen confli1 = F1.e_miinterc

* Life expectation
* Generate year and country dummies dummies
tabulate country_name if gdpgro2 != . & ps != . & lifeex1 != . & e_migdppcln != ., generate(cn)
tabulate year if gdpgro2 != . & ps != . & lifeex1 != . & e_migdppcln != ., generate(yr)

* Mediation analysis
medeff (regress lifeex1 ps e_migdppcln cn2-cn151 yr2-yr109) (regress gdpgro2 lifeex1 ps e_migdppcln cn2-cn151 yr2-yr109), mediate(lifeex1) treat(ps) vce(robust)

* Drop Variables
drop cn* yr*

* Infant Mortality
* Generate year and country dummies dummies
tabulate country_name if gdpgro2 != . & ps != . & infmor1 != . & e_migdppcln != ., generate(cn)
tabulate year if gdpgro2 != . & ps != . & infmor1 != . & e_migdppcln != ., generate(yr)

* Mediation analysis
medeff (regress infmor1 ps e_migdppcln cn2-cn150 yr2-yr109) (regress gdpgro2 infmor1 ps e_migdppcln cn2-cn150 yr2-yr109), mediate(infmor1) treat(ps) vce(robust)

* Drop Variables
drop cn* yr*

* Investment
* Generate year and country dummies dummies
tabulate country_name if gdpgro2 != . & ps != . & invest1 != . & e_migdppcln != ., generate(cn)
tabulate year if gdpgro2 != . & ps != . & invest1 != . & e_migdppcln != ., generate(yr)

* Mediation analysis
medeff (regress invest1 ps e_migdppcln cn2-cn148 yr2-yr60) (regress gdpgro2 invest1 ps e_migdppcln cn2-cn148 yr2-yr60), mediate(invest1) treat(ps) vce(robust)

* Drop Variables
drop cn* yr*

* Inflation
* Generate year and country dummies dummies
tabulate country_name if gdpgro2 != . & ps != . & inflat1 != . & e_migdppcln != ., generate(cn)
tabulate year if gdpgro2 != . & ps != . & inflat1 != . & e_migdppcln != ., generate(yr)

* Mediation analysis
medeff (regress inflat1 ps e_migdppcln cn2-cn144 yr2-yr109) (regress gdpgro2 inflat1 ps e_migdppcln cn2-cn144 yr2-yr109), mediate(inflat1) treat(ps) vce(robust)

* Drop Variables
drop cn* yr*

* Exit Irregular
* Generate year and country dummies dummies
tabulate country_name if gdpgro2 != . & ps != . & exitir1 != . & e_migdppcln != ., generate(cn)
tabulate year if gdpgro2 != . & ps != . & exitir1 != . & e_migdppcln != ., generate(yr)

* Mediation analysis
medeff (regress exitir1 ps e_migdppcln cn2-cn141 yr2-yr109) (regress gdpgro2 exitir1 ps e_migdppcln cn2-cn141 yr2-yr109), mediate(exitir1) treat(ps) vce(robust)

* Drop Variables
drop cn* yr*

* Internal Conflict
* Generate year and country dummies dummies
tabulate country_name if gdpgro2 != . & ps != . & confli1 != . & e_migdppcln != ., generate(cn)
tabulate year if gdpgro2 != . & ps != . & confli1 != . & e_migdppcln != ., generate(yr)

* Mediation analysis
medeff (regress confli1 ps e_migdppcln cn2-cn111 yr2-yr109) (regress gdpgro2 confli1 ps e_migdppcln cn2-cn111 yr2-yr109), mediate(confli1) treat(ps) vce(robust)

* Drop Variables
drop cn* yr*

*--------
* Table J2. Party Strength predicts mediators
*--------

eststo clear

* Reload full data
use "C:\Users\fbizz\Dropbox\Party strength\Empirics\Data\ps_data.dta", clear
xtset, clear
xtset country_id year

* Life expectancy
gen lifeex = ln(85-e_pelifeex)
eststo mod2: xtreg F.lifeex ps  e_migdppcln i.year, fe vce(cluster country_id)

* Infant Mortality
gen infmor = ln(e_peinfmor)
eststo mod3: xtreg F.infmor ps e_migdppcln i.year, fe vce(cluster country_id)

* Investiments
eststo mod4: xtreg F.pwt_isg ps e_migdppcln i.year, fe vce(cluster country_id)

* Inflation
gen inflat = ln(e_miinflat)
eststo mod5: xtreg F.inflat ps e_migdppcln i.year, fe vce(cluster country_id)

* Exit Irregular
eststo mod6: xtreg F.exit_1_irregular ps e_migdppcln i.year, fe vce(cluster country_id)

* Internal Conflict
eststo mod7: xtreg F.e_miinterc ps e_migdppcln i.year, fe vce(cluster country_id)

esttab _all using "C:\Users\fbizz\Dropbox\Party strength\Empirics\Tables\table_extension_mediators.csv", ///
		b(3) se(3)  ///
		stats(N N_g g_min g_avg g_max r2_w, labels("Obs" "Countries" "Min # Years" "Avg # Years" "Max # Years" "R-squared (within)")) ///
		legend label nomtitles ///
		star(* 0.10 ** 0.05 *** 0.01) ///
		drop(*.year) ///
		noconstant ///
		nogaps replace

